@include('admin.layout.bone_header')

<div class="layui-form layui-form-pane search">
    <div class="layui-form-item">
        <label class="layui-form-label">项目id</label>
        <div class="layui-input-inline">
            <input type="text" id="project_id" autocomplete="off" placeholder="请输入项目id" class="layui-input">
        </div>
        <label class="layui-form-label">卡密值</label>
        <div class="layui-input-inline">
            <input type="text" id="project_pass_value" autocomplete="off" placeholder="请输入卡密值" class="layui-input">
        </div>
        <button class="layui-btn" data-type="reload">添加</button>
    </div>
</div>



<table class="layui-hide" id="think-table" lay-filter="think-table"></table>

<script type="text/html" id="barDemo">
    @{{# if(d.user_id == 0){ }}
        <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>
    @{{# } }}


</script>

<script>

    layui.use('table', function () {
        let table = layui.table;
        UI.getPageTable(table, "{{route('admin.project_pass.lists')}}", [
            {field: 'project_pass_id', title: 'ID', width: 80, sort: true, fixed: 'left'}
            , {field: 'project_id', title: '项目id'}
            , {field: 'project_pass_value', title: '项目卡密'}
            ,{field: 'created_at',title:'卡密分配人',templet:function (d){
                   if(d['user_id'] == 0){
                       return '未分配';
                   }else{
                       return d['user_info']['nickname']+'-'+d['user_info']['user_phone'];
                   }
                }}
            ,{field: 'created_at',title:'卡密创建时间',templet:function (d){
                    return layui.util.toDateString(parseInt(d['created_at'])*1000,'yyyy-MM-dd HH:mm:ss')
                }}
            ,{fixed: 'right',title:'操作', align:'center', toolbar: '#barDemo'}
        ]);

        table.on('tool(think-table)', function (obj) {
            let data = obj.data;
             if(obj.event == 'del'){
                UI.delete(data['project_pass_id'],function(res){
                    table.reload('think-table');
                },"{{route('admin.project_pass.del_pass')}}");
            }
        });
        let $ = layui.$, active = {
            reload:function (){
                HttpUtils.post('{{route('admin.project_pass.lists')}}',{
                    'project_pass_value':$("#project_pass_value").val(),
                    'project_id':$("#project_id").val()
                },function (res){
                    if(res['code'] == 200){
                        $("#project_pass_value").val("")
                        $("#project_id").val("")
                        table.reload("think-table");
                        Utils.successToast(res['msg'])
                        return;
                    }
                    Utils.errorToast(res['msg'])
                });
            }
        };
        $('.layui-btn-container .layui-btn').on('click', function () {
            let type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        $('.search .layui-btn').on('click', function () {
            let type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    })


</script>


@include('admin.layout.bone_footer')
